<template>
    <Layout>
        <div>
            <el-card class="box-card">




                <p>

                    <el-descriptions title="广西标准化协会团体标准发布统计表" :column="1" border>

                    </el-descriptions>
                </p>
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">
                    <el-form-item label="序号">
                        <span>{{ list.id }}</span>
                    </el-form-item>
                    <el-form-item label="立项编号" prop="projectNumber">
                        <el-input v-model="ruleForm.projectNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="标准名称" prop="standardName">
                        <el-input v-model="ruleForm.standardName"></el-input>
                    </el-form-item>
                    <el-form-item label="标准性质" prop="standardNature">
                        <el-input v-model="ruleForm.standardNature"></el-input>
                    </el-form-item>
                    <el-form-item label="制定或修订" prop="formulate">
                        <el-input v-model="ruleForm.formulate"></el-input>
                    </el-form-item>
                    <el-form-item label="起止年限" prop="addTime">
                        <el-input v-model="ruleForm.addTime"></el-input>
                    </el-form-item>
                    <el-form-item label="采用国际标准或国外先进标准" prop="advancedStandards">
                        <el-input v-model="ruleForm.advancedStandards"></el-input>
                    </el-form-item>
                    <el-form-item label="团体标准提出单位" prop="groupProposing">
                        <el-input v-model="ruleForm.groupProposing"></el-input>
                    </el-form-item>
                    <el-form-item label="主要负责起草单位" prop="draftingUnit">
                        <el-input v-model="ruleForm.draftingUnit"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" prop="name">
                        <el-input v-model="ruleForm.remark"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
                        <el-button @click="resetForm">返回</el-button>
                    </el-form-item>
                </el-form>

            </el-card>


        </div>
    </Layout>
</template>
<script>
import Layout from '@/components/Layout.vue';
import axios from 'axios';
export default {
    data() {
        return {
            ruleForm: {
                projectNumber: "",
                standardName: '',
                standardNature: '',
                formulate: '',
                addTime: '',
                advancedStandards: '',
                groupProposing: '',
                draftingUnit: '',
                remark: ''
            },
            rules: {
                projectNumber: [
                    { required: true, message: '请输入立项编号', trigger: 'blur' },

                ],
                standardName: [
                    { required: true, message: '请输入标准名称', trigger: 'blur' },

                ],
            },
            list: []
        }
    },
    created() {
        const { cid } = this.$route.params
        axios({
            url: "http://43.143.166.235:8090/program/select?id=" + cid
        }).then(res => {
            console.log(res)
            this.list = res.data
            this.ruleForm.projectNumber = this.list.projectNumber
            this.ruleForm.standardName = this.list.standardName
            this.ruleForm.standardNature = this.list.standardNature
            this.ruleForm.formulate = this.list.formulate
            this.ruleForm.addTime = this.list.addTime
            this.ruleForm.advancedStandards = this.list.advancedStandards
            this.ruleForm.groupProposing = this.list.groupProposing
            this.ruleForm.draftingUnit = this.list.draftingUnit
            this.ruleForm.remark = this.list.remark
        })
    },
    components: {
        Layout
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    axios({
                        url: "http://43.143.166.235:8090/program/update",
                        method: "post",
                        data: {
                            "projectNumber": this.ruleForm.projectNumber,
                            "standardName": this.ruleForm.standardName,
                            "standardNature": this.ruleForm.standardNature,
                            "formulate": this.ruleForm.formulate,
                            "addTime": this.ruleForm.addTime,
                            "advancedStandards": this.ruleForm.advancedStandards,
                            "groupProposing": this.ruleForm.groupProposing,
                            "draftingUnit": this.ruleForm.draftingUnit,
                            "remark": this.ruleForm.remark
                        }
                    }).then(res => {
                        console.log(res)
                    })
                    alert('修改成功!');
                    this.$router.push({
                        name: 'program'
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm() {
            this.$router.push({
                name: 'booklist'
            })
        }
    }
}


</script>
<style>
.box-card {
    height: calc(100vh - 60px);
}
</style>